package ControlLayer;

import java.util.ArrayList;
import DBLayer.DbConnection;
import DBLayer.DbZipCode;
import DBLayer.IfDbZipCode;
import ModelLayer.ZipCode;

public class ZipCodeCtrl
{
	public ArrayList<ZipCode> findAllInvoices()
    {
        IfDbZipCode dbInvoice = new DbZipCode();
        ArrayList<ZipCode> allInvoices = new ArrayList<ZipCode>();
        allInvoices = dbInvoice.getAllZipCodes(false);
        return allInvoices;
    }
    public ZipCode findInvoicesByPaymentDate(String zipCode)
    {
    	IfDbZipCode dbInvoice = new DbZipCode();
        return dbInvoice.findZipCodeByZipCode(zipCode, true);
    }
    public void insertZipCode(String zipCode)
    {
    	ZipCode zipCodeObject = new ZipCode();
    	zipCodeObject.setZipcode(zipCode);
 
        try
        {
            DbConnection.startTransaction();
            DbZipCode dbZipcode = new DbZipCode();
            dbZipcode.insertZipCode(zipCodeObject);
            DbConnection.commitTransaction();
        }
        catch(Exception e)
        {
            DbConnection.rollbackTransaction();
        }
    }

    public int updateZipCode(String zipCode)
    {
    	IfDbZipCode dbZipcode = new DbZipCode();
        ZipCode zipcode = new ZipCode();
        zipcode.setZipcode(zipCode);
        return dbZipcode.updateZipCode(zipcode);
    }
    
    public int deleteZipCode(String zipCode)
    {
    	IfDbZipCode dbZipcode = new DbZipCode();
    	return dbZipcode.deleteZipCode(zipCode);
    }
}